package cs4;

import java.util.Calendar;
import java.util.Date;

/*
 * Calendar:日历类的使用
 */
public class DateTest2 {
    public static void main(String[] args) {
        //1.实例化
        //方式一:创建其子类GregorianCalendar的对象
        //方式二:调用其静态方法getInstance()
        Calendar calendar=Calendar.getInstance();
        //2.常用方法
        //get()
        int days=calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(days);
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        //set()
        calendar.set(Calendar.DAY_OF_MONTH, 22);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        //add()
        calendar.add(Calendar.DAY_OF_MONTH, 5);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        //getTime()
        Date date = calendar.getTime();
        System.out.println(date);
        Date date1 = new Date();
        calendar.setTime(date1);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
    }
}
